package cn.jnetty.ioc.mapping;

import cn.jnetty.api.exception.JnettyIocException;
import cn.jnetty.api.handler.RouterHandler;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 猪哥亮
 * @email 1030681978@qq.com
 * @date 2020/4/6 18:49
 * 描述：
 */
public class JRequestDefinitionBeanFactory {
    private static class Singleton{
        public static final JRequestDefinitionBeanFactory INSTANCE = new JRequestDefinitionBeanFactory();
    }
    public static JRequestDefinitionBeanFactory getInstance(){
        return Singleton.INSTANCE;
    }
    private Map<String, RouterHandler> map = new HashMap<>();
    public void put(JRequestDefinitionBean bean, RouterHandler resolver){
        if(bean == null){
            return;
        }
        if(map.containsKey(bean.getPath())){
            throw new JnettyIocException("请求端口映射重复{0}在{1}方法{2}",bean.getPath(),bean.getObj().getClass(), bean.getMethod());
        }
        map.put(bean.getPath(),resolver);
    }
    public RouterHandler getBean(String path){
        return map.getOrDefault(path,null);
    }
}
